Skip to content

Conversation

@david-zlai
Copy link
Contributor

@david-zlai david-zlai commented Jun 12, 2025

Summary

Checklist

  • Added Unit Tests
  • Covered by existing CI
  • Integration tested
  • Documentation update

Summary by CodeRabbit

  • New Features
    • Introduced utilities for loading CSV data into Spark tables with automatic timestamp parsing.
  • Tests
    • Added new test cases to validate label join behavior using external CSV fixtures, covering scenarios with and without sub-day window rounding.
  • Chores
    • Made test resources explicitly available to the batch test suite.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

This update introduces new test utilities for loading CSV data and parsing timestamps, adds explicit test resources to the batch_test suite, and expands the LabelJoinV2Test with tests using CSV fixtures to validate label join logic under different sub-day window rounding configurations.

Changes

File(s) Change Summary
spark/BUILD.bazel Added data attribute to batch_test scala_test_suite for test resources.
spark/src/test/scala/ai/chronon/spark/test/TestUtils.scala Added utility methods for loading CSV data and converting timestamp columns.
spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala Added helper for fixture-based joins and two new tests covering label join behavior with/without rounding.

Sequence Diagram(s)

sequenceDiagram
    participant Test as LabelJoinV2Test
    participant Utils as TestUtils
    participant Table as TableTestUtils
    participant Spark as SparkSession

    Test->>Utils: createTableWithCsvData(...)
    Utils->>Utils: createDataframeFromCsv(...)
    Utils->>Spark: Read CSV, convert timestamp
    Utils->>Table: insertPartitions(DataFrame)
    Test->>Table: Setup tables for join
    Test->>Test: Run label join with/without rounding flag
    Test->>Spark: Assert DataFrame equality
Loading

Possibly related PRs

Suggested reviewers

  • varant-zlai
  • nikhil-zlai

Poem

In the land where labels join and meet,
CSVs now march in rows so neat.
With tests for rounding, tight and loose,
Data flows—no more excuse!
Spark and Scala, hand in hand,
Test resources at their command.
🧪✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e88771 and 6da69d5.

📒 Files selected for processing (1)
  • spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: streaming_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: groupby_tests
  • GitHub Check: spark_tests
  • GitHub Check: join_tests
  • GitHub Check: batch_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: enforce_triggered_workflows

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@david-zlai david-zlai requested a review from varant-zlai June 12, 2025 22:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala (1)

830-838: Same issue for the round-down session

Add

import sparkRoundDownWithFixture.implicits._

right after the session is created.

🧹 Nitpick comments (2)
spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala (1)

679-707: Use Bazel Runfiles API instead of manual RUNFILES_DIR concat

Hard-coding:

val runfilesDir = System.getenv("RUNFILES_DIR")
Paths.get(runfilesDir, "chronon/...")

works only when that env-var is present and the path layout stays constant.
Prefer:

val runfiles = com.google.devtools.build.runfiles.Runfiles.create()
val csvPath  = runfiles.rlocation("chronon/spark/src/test/resources/local_data_csv/sample_join.csv")

This survives all Bazel runfiles quirks and Windows paths.

spark/src/test/scala/ai/chronon/spark/test/TestUtils.scala (1)

454-473: CSV utilities – make parsing deterministic

  1. inferSchema = true makes tests flaky when the sample set changes.
    Pass an explicit StructType or keep inferSchema = false with predefined column types.

  2. unix_timestamp uses the session timezone; tests may break on machines with a non-UTC TZ.
    Consider to_utc_timestamp or set spark.sql.session.timeZone explicitly inside the reader.

  3. When tsColName != "ts" the original string column stays behind.
    If not needed, drop it to avoid clutter:

.withColumn("ts", (unix_timestamp(col(tsColName), tsFormat) * 1000).cast("long"))
.drop(tsColName)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44b0958 and 3e88771.

⛔ Files ignored due to path filters (3)
  • spark/src/test/resources/local_data_csv/sample_join.csv is excluded by !**/*.csv
  • spark/src/test/resources/local_data_csv/sample_label_loose_source.csv is excluded by !**/*.csv
  • spark/src/test/resources/local_data_csv/sample_label_tight_source.csv is excluded by !**/*.csv
📒 Files selected for processing (3)
  • spark/BUILD.bazel (1 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/TestUtils.scala (2 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: fetcher_tests
  • GitHub Check: join_tests
  • GitHub Check: groupby_tests
  • GitHub Check: streaming_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: spark_tests
  • GitHub Check: batch_tests
🔇 Additional comments (2)
spark/src/test/scala/ai/chronon/spark/test/batch/LabelJoinV2Test.scala (1)

780-827: Schema mismatch risk in hard-coded expected DataFrames

expectedMay4Df builds the ts column as a string, whereas the fixture loader casts it to LongType.
DataFrame.except requires identical schemas and will fail if labelComputedMay4.ts is LongType.
Cast explicitly to keep types aligned:

-("1746266400000",
+1746266400000L,

or .cast("long") after construction.

spark/BUILD.bazel (1)

147-148: Good addition – resources now available to batch_test

Including //spark/src/test/resources:test-resources in data ensures the CSV fixtures land in runfiles. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants